home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / pcscheme / geneva / sources.exe / SOURCES / ASM / BORDER.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-01-25  |  13.2 KB  |  489 lines

  1. ;* BORDER.ASM
  2. ;************************************************************************
  3. ;*                                    *
  4. ;*        PC Scheme/Geneva 4.00 Borland TASM code            *
  5. ;*                                    *
  6. ;* (c) 1985-1988 by Texas Instruments, Inc. See COPYRIGHT.TXT        *
  7. ;* (c) 1992 by L. Bartholdi & M. Vuilleumier, University of Geneva    *
  8. ;*                                    *
  9. ;*----------------------------------------------------------------------*
  10. ;*                                    *
  11. ;*            Window Borders, etc.                *
  12. ;*                                    *
  13. ;*----------------------------------------------------------------------*
  14. ;*                                    *
  15. ;* Created by: John Jensen        Date: 1985            *
  16. ;* Revision history:                            *
  17. ;* - 18 Jun 92:    Renaissance (Borland Compilers, ...)            *
  18. ;*                                    *
  19. ;*                    ``In nomine omnipotentii dei''    *
  20. ;************************************************************************
  21. IDEAL
  22. %PAGESIZE    60, 132
  23. MODEL    medium
  24. LOCALS    @@
  25.  
  26.     INCLUDE    "scheme.ash"
  27.  
  28. CODESEG
  29.  
  30. ;************************************************************************
  31. ;*                 Draw Border                *
  32. ;************************************************************************
  33. PROC C    zborder USES si di, @@line, @@col, @@nlines, @@ncols, @@attr, @@label, @@args
  34.     call    get_max_rows C
  35.     mov    ch, al
  36.     call    get_max_cols C
  37.     mov    cl, al
  38.     mov    bl, [BYTE @@attr]
  39.     mov    dl, [BYTE @@col]
  40.     mov    dh, [BYTE @@line]
  41.     dec    dl
  42.     dec    dh
  43.     mov    al, 0dah         ; load upper left corner character
  44.     call    zcorner
  45.     inc    dl
  46.     add    dl, [BYTE @@ncols]
  47.     mov    al, 0bfh         ; load upper right corner character
  48.     call    zcorner
  49.     inc    dh
  50.     add    dh, [BYTE @@nlines]
  51.     mov    al, 0d9h         ; load lower right corner character
  52.     call    zcorner
  53.     dec    dl
  54.     sub    dl, [BYTE @@ncols]
  55.     mov    al, 0c0h         ; load lower left corner character
  56.     call    zcorner
  57.  
  58.     mov    dl, [BYTE @@col]     ; reload upper left corner
  59.     mov    dh, [BYTE @@line]
  60.     dec    dl
  61.     jl    @@noleftside
  62.     mov    bh, [BYTE @@nlines]
  63.     call    zside             ; draw the left hand border
  64.     mov    dh, [BYTE @@line]
  65. @@noleftside:
  66.     inc    dl
  67.     add    dl, [BYTE @@ncols]
  68.     cmp    dl, cl
  69.     jae    @@norightside
  70.     mov    bh, [BYTE @@nlines]
  71.     call    zside             ; draw the right hand border
  72.     mov    dh, [BYTE @@line]
  73. @@norightside:
  74.     dec    dh
  75.     jl    @@noupperside
  76.     mov    dl, [BYTE @@col]
  77.     mov    bh, [BYTE @@ncols]
  78.     call    ztop            ; draw upper lide
  79.  
  80.     push    cx            ; saves max rows and cols
  81.     mov    bx, [@@label]        ; get label
  82.     or    bx, bx             ; if pointer NULL, no label
  83.     jz    @@noupperlabel
  84.     mov    dx, [@@ncols]
  85.     xor    cx, cx
  86. @@testlabel:
  87.     cmp    [BYTE bx], 0        ; end of string?
  88.     je    @@endofstring
  89.     inc    cx             ; inc count
  90.     inc    bx             ; inc string pointer
  91.     cmp    cx, dx             ; compare to window width
  92.     jl    @@testlabel
  93. @@endofstring:
  94.     jcxz    @@noupperlabel
  95.     push    cx
  96.     mov    dh, [BYTE @@line]    ; load upper left corner
  97.     mov    dl, [BYTE @@col]
  98.     dec    dh
  99.     xor    bh, bh             ; use page 0
  100.     mov    ah, 02h
  101.     int    IBM_CRT         ; put cursor in upleft corner of border
  102.     pop    cx
  103.     mov    di, [@@label]         ; load label offset
  104. @@writelabel:
  105.     mov    ah, 0eh         ; Write ASCII Teletype
  106.     mov    al, [BYTE di]
  107.     mov    bl, [BYTE @@attr]     ; load attribute bits just in case
  108.     xor    bh, bh
  109.     push    cx di
  110.     int    IBM_CRT            ; display label char
  111.     pop    di cx
  112.     inc    di
  113.     loop    @@writelabel
  114. @@noupperlabel:
  115.     pop    cx
  116.     mov    bl, [BYTE @@attr]
  117. @@noupperside:
  118.     mov    dl, [BYTE @@col]
  119.     mov    dh, [BYTE @@line]
  120.     add    dh, [BYTE @@nlines]
  121.     cmp    dh, ch
  122.     ja    @@nolowerside
  123.     mov    bh, [BYTE @@ncols]
  124.     call    ztop
  125. @@nolowerside:
  126.     ret
  127. ENDP    zborder
  128.  
  129. ;************************************************************************
  130. ;* Local Support:  Draw a single character at cursor position        *
  131. ;*                                    *
  132. ;* Input Registers:  al - the character to be output            *
  133. ;*             bl - the character attributes for the write    *
  134. ;*             dl - column                    *
  135. ;*             dh - row                        *
  136. ;*             cl - max column                    *
  137. ;*             ch - max row                    *
  138. ;*                                    *
  139. ;* Registers Modified:    ax, si, di                    *
  140. ;************************************************************************
  141. PROC    zcorner    near
  142.     cmp    dl, cl            ; ensure char written within CRT
  143.     ja    @@return
  144.     cmp    dh, ch
  145.     ja    @@return
  146.     push    bx cx dx
  147.     push    ax             ; save character to be output
  148.     xor    bh, bh
  149.     mov    ah, 02h
  150.     int    IBM_CRT         ; position the cursor
  151.     xor    bh, bh
  152.     mov    ah, 08h
  153.     int    IBM_CRT            ; read current char on the screen
  154.     call    map_char
  155.     mov    si, ax
  156.     pop    ax             ; recover character to be output
  157.     or    si, si
  158.     jl    @@putcorner
  159.     call    map_char
  160.     mov    cl, OFFSET @@next - OFFSET @@table
  161.     mul    cl
  162.     add    si, ax
  163.     mov    al, [@@table+si]
  164. DATASEG
  165. @@table DB    0dah, 0c2h, 0c3h, 0c5h, 0c3h, 0c2h, 0c2h, 0c5h, 0c3h, 0c5h, 0c5h
  166. @@next    DB    0c2h, 0bfh, 0c5h, 0b4h, 0b4h, 0c2h, 0c2h, 0c5h, 0c5h, 0b4h, 0c5h
  167.     DB    0c3h, 0c5h, 0c0h, 0c1h, 0c3h, 0c1h, 0c5h, 0c1h, 0c3h, 0c5h, 0c5h
  168.     DB    0c5h, 0b4h, 0c1h, 0d9h, 0b4h, 0c1h, 0c5h, 0c1h, 0c5h, 0b4h, 0c5h
  169.     DB    0c3h, 0b4h, 0c3h, 0b4h, 0b3h, 0c5h, 0c5h, 0c5h, 0c3h, 0b4h, 0c5h
  170.     DB    0c2h, 0c2h, 0c1h, 0c1h, 0c5h, 0c4h, 0c2h, 0c1h, 0c5h, 0c5h, 0c5h
  171. CODESEG
  172. @@putcorner:
  173.     mov    ah, 09h            ; output the corner character
  174.     mov    cx, 1
  175.     xor    bh, bh
  176.     int    IBM_CRT         ; write char & attrib to the screen
  177.     pop    dx cx bx
  178. @@return:
  179.     ret
  180. ENDP    zcorner
  181.  
  182. ;************************************************************************
  183. ;* Local Support:  Draw a border sides                    *
  184. ;*                                    *
  185. ;* Input Registers:  dl - column                    *
  186. ;*             dh - row                        *
  187. ;*             bl - attribute                    *
  188. ;*             bh - number of rows                *
  189. ;*             cl - max column                    *
  190. ;*             ch - max row                    *
  191. ;*                                    *
  192. ;* Registers Modified:    ax, bh, dl, si                    *
  193. ;************************************************************************
  194. PROC    zside    near
  195. @@loop:
  196.     mov    al, 0b3h         ; load "|" border character
  197.     call    zcorner         ; output the border character
  198.     inc    dh             ; increment the row number
  199.     dec    bh
  200.     jnz    @@loop
  201. @@return:
  202.     ret
  203. ENDP    zside
  204.  
  205. ;************************************************************************
  206. ;* Local Support:  Draw a border - Top or Bottom            *
  207. ;*                                    *
  208. ;* Input Registers:  dl - column                    *
  209. ;*             dh - row                        *
  210. ;*             bl - attribute                    *
  211. ;*             bh - number of columns                *
  212. ;*             cl - max column                    *
  213. ;*             ch - max row                    *
  214. ;*                                    *
  215. ;* Registers Modified:    ax, cx, si, di                    *
  216. ;************************************************************************
  217. PROC    ztop    near
  218. @@loop:
  219.     mov    al, 0c4h         ; load "-" border character
  220.     call    zcorner         ; output the border character
  221.     inc    dl             ; increment the column number
  222.     dec    bh
  223.     jnz    @@loop
  224. @@return:
  225.     ret
  226. ENDP    ztop
  227.  
  228. ;************************************************************************
  229. ;* Local support: map a border character                *
  230. ;************************************************************************
  231. PROC    map_char near
  232.     mov    cx, OFFSET @@next - OFFSET @@table
  233.     lea    di, [@@table]
  234.     repne    scasb
  235.     mov    ax, cx
  236.     dec    ax
  237.     ret
  238. DATASEG
  239. @@table    DB    0c5h, 0b4h, 0c3h, 0c1h, 0c2h, 0c4h, 0b3h, 0d9h, 0c0h, 0bfh, 0dah, 0dah
  240. LABEL    @@next    BYTE
  241. CODESEG
  242. ENDP    map_char
  243.  
  244. ;************************************************************************
  245. ;*            Save Screen Contents                *
  246. ;*                                    *
  247. ;* Purpose:  To save a rectangular region of the CRT in a string data    *
  248. ;*        object.                         *
  249. ;*                                    *
  250. ;* Calling Sequence:  save_scr(str_reg, ul_row, ul_col, n_rows, ncols)    *
  251. ;*            where str_reg - pointer to string data object    *
  252. ;*                    which is to receive the screen    *
  253. ;*                    contents            *
  254. ;*                  ul_row - row number of the upper left    *
  255. ;*                    corner of the region to be    *
  256. ;*                    saved                *
  257. ;*                  ul_col - column number of the upper left    *
  258. ;*                    corner of the region to be    *
  259. ;*                    saved                *
  260. ;*                  n_rows - number of rows in the region to    *
  261. ;*                    be saved            *
  262. ;*                  n_cols - number of columns in the region    *
  263. ;*                    to be saved            *
  264. ;************************************************************************
  265. PROC C    save_scr USES si di, @@str, @@ulrow, @@ulcol, @@nrow, @@ncol, @@args
  266.     LOCAL    @@vidmode:BYTE, @@lastback:BYTE, @@lastfore:BYTE
  267.     call    is_graph_mode C
  268.     mov    [@@vidmode], al
  269.     mov    [@@lastfore], 0fh    ; a good guess is bright white
  270.     mov    [@@lastback], 0        ; on a black background
  271.  
  272.     mov    bx, [@@str]        ; create a pointer to the string object
  273.     mov    di, [(REG bx).disp]
  274.     mov    bx, [(REG bx).page]
  275.     ldpage    es, bx
  276.     lea    di, [(STRDEF di).buffer]
  277.     mov    al, [BYTE @@nrow]    ; store #rows & columns into the first two bytes
  278.     stosb
  279.     mov    al, [BYTE @@ncol]
  280.     stosb
  281.     mov    ax, [@@ulrow]        ; adjust number of lines/columns for test conditions
  282.     add    [@@nrow], ax
  283.     mov    ax, [@@ulcol]
  284.     add    [@@ncol], ax
  285.     mov    dh, [BYTE @@ulrow]
  286. @@rowloop:
  287.     mov    dl, [BYTE @@ulcol]
  288. @@colloop:
  289.     push    di            ; some BIOSes don't save it
  290.     mov    ah, 02h
  291.     xor    bh, bh            ; page 0
  292.     int    IBM_CRT         ; position the cursor (page zero)
  293.     mov    ah, 08h
  294.     xor    bh, bh            ; page 0
  295.     int    IBM_CRT         ; "read char/attribute" function
  296.     cmp    [@@vidmode], 0
  297.     jz    @@textmode
  298.                     ; we now have al=char, ah=nonsense.
  299.                     ; we have to detect the attribute.
  300.     cmp    al, 0dbh        ; is it a blot ?
  301.     je    @@findbackground
  302.     mov    [@@lastback], 0        ; this is a black background
  303.     jmp    @@findforeground
  304.  
  305. @@findbackground:
  306.     mov    bh, [@@lastback]
  307.     call    tryattr
  308.     je    @@igiveup
  309.     mov    [@@lastback], ah
  310.     mov    ah, 08h            ; now REALLY read it
  311.     xor    bh, bh            ; page 0
  312.     int    IBM_CRT
  313. @@findforeground:
  314.     or    al, al
  315.     jne    @@goahead
  316.     mov    al, 0dbh
  317.     mov    bl, [@@lastback]
  318.     call    putchar
  319. @@igiveup:
  320.     mov    al, ' '
  321.     jmp    @@done
  322. @@goahead:
  323.     mov    bh, [@@lastfore]
  324.     call    tryattr
  325.     je    @@done
  326.     mov    [@@lastfore], ah
  327.     mov    bl, ah
  328.     call    putchar
  329.     mov    bl, [@@lastback]
  330.     or    bl, bl
  331.     jz    @@done
  332.     push    ax
  333.     mov    al, 0dbh        ; write a blot (restore background)
  334.     call    putchar
  335.     pop    ax
  336. @@done:
  337.     mov    bl, [@@lastback]    ; in case we didn't find anything,
  338.                     ; assume previous one is OK
  339.     xor    ah, bl            ; adjust foreground
  340.     mov    cl, 4
  341.     shl    bx, cl
  342.     or    ah, bl
  343.     and    ah, 7fh            ; mask off the intensity bit
  344. @@textmode:
  345.     pop    di
  346.     stosw                ; store char/attr into output string
  347.     inc    dl            ; next column
  348.     cmp    dl, [BYTE @@ncol]
  349.     jb    @@colloop
  350.     inc    dh            ; next line
  351.     cmp    dh, [BYTE @@nrow]
  352.     jb    @@rowloop
  353.     ret
  354. ENDP    save_scr
  355.  
  356. ;************************************************************************
  357. ;* Local support: test if character is readable                *
  358. ;* Assumes:    al = char                        *
  359. ;*        bh = first attribute to try                *
  360. ;* This routine will test if al can be read at the cursor position, and *
  361. ;* then write al using attributes bl. AX, BX, CX, DX are preserved.    *
  362. ;* The result is in ZF                            *
  363. ;*                                    *
  364. ;************************************************************************
  365. PROC    tryattr near
  366.     push    dx
  367.     xor    ah, ah            ; ah is current try, bh next one
  368.     mov    cx, 16            ; try 16 colors
  369. @@loop:
  370.     mov    bl, bh            ; this is how to change
  371.     xor    bl, ah
  372.     or    bl, 80h            ; write using XOR
  373.     mov    ah, bh            ; new becomes old
  374.     inc    bh
  375.     and    bh, 0fh            ; next guess
  376.     push    cx bx ax
  377.     mov    ah, 09h            ; write new char
  378.     xor    bh, bh
  379.     mov    cx, 1            ; 1 char
  380.     int    IBM_CRT
  381.     pop    ax
  382.     push    ax
  383.     mov    ah, 08h            ; read char/attr
  384.     xor    bh, bh            ; page 0
  385.     int    IBM_CRT
  386.     mov    dx, ax
  387.     pop    ax            ; restore old char
  388.     cmp    al, dl            ; same as before ?
  389.     pop    bx cx
  390.     loope    @@loop
  391.     pop    dx
  392.     ret
  393. ENDP    tryattr
  394.  
  395. ;************************************************************************
  396. ;* Local support: write the char al with attributes bl            *
  397. ;************************************************************************
  398. PROC    putchar near
  399.     push    ax bx cx
  400.     mov    ah, 09h
  401.     xor    bh, bh
  402.     or    bl, 80h
  403.     mov    cx, 1
  404.     int    IBM_CRT
  405.     pop    cx bx ax
  406.     ret
  407. ENDP    putchar
  408.  
  409. ;************************************************************************
  410. ;*            Restore Screen Contents             *
  411. ;*                                    *
  412. ;* Purpose:  To restore a rectangular region of the CRT from a string    *
  413. ;*        data object.                        *
  414. ;*                                    *
  415. ;* Calling Sequence:  rest_scr(str_reg, ul_row, ul_col)         *
  416. ;*            where str_reg - pointer to string data object    *
  417. ;*                    which contains the screen    *
  418. ;*                    contents            *
  419. ;*                  ul_row - row number of the upper left    *
  420. ;*                    corner of the region to be    *
  421. ;*                    restored            *
  422. ;*                  ul_col - column number of the upper left    *
  423. ;*                    corner of the region to be    *
  424. ;*                    restored            *
  425. ;************************************************************************
  426. PROC C    rest_scr USES si di, @@str, @@ulrow, @@ulcol, @@maxrow, @@maxcol
  427.     LOCAL    @@ncol, @@nrow, @@vidmode
  428.     mov    [@@vidmode], -1
  429.     mov    bx, [@@str]        ; create a pointer to the string object
  430.     mov    si, [(REG bx).disp]
  431.     mov    bx, [(REG bx).page]
  432.     ldpage    es, bx
  433.     lea    si, [(STRDEF si).buffer]
  434.     xor    ax, ax            ; recover # rows & col from screen object
  435.     lods    [BYTE es:si]
  436.     add    ax, [@@ulrow]
  437.     mov    [@@nrow], ax
  438.     lods    [BYTE es:si]
  439.     add    ax, [@@ulcol]
  440.     mov    [@@ncol], ax
  441.     mov    ax, [@@ulrow]        ; adjust # of lines/columns for conditions
  442.     add    [@@maxrow], ax
  443.     mov    ax, [@@ulcol]
  444.     add    [@@maxcol], ax
  445.     xor    bx, bx            ; char count
  446.     mov    dh, [BYTE @@ulrow]
  447. @@rowloop:
  448.     xor    bl, bl
  449.     mov    cx, [WORD es:si]    ; prev char = first char of line
  450.     mov    dl, [BYTE @@ulcol]
  451. @@colloop:
  452.     lods    [WORD es:si]        ; fetch char from buffer
  453.     cmp    dl, [BYTE @@maxcol]    ; line too long for new window?
  454.     jnb    @@nextchar
  455.     cmp    cx, ax            ; same char as previous one ?
  456.     jne    @@writechars
  457.     inc    bl
  458. @@nextchar:
  459.     inc    dl            ; next column
  460.     cmp    dl, [BYTE @@ncol]
  461.     jb    @@colloop
  462. @@writechars:
  463.     push    ax cx si dx
  464.     sub    dl, bl            ; position at begin of replication
  465.     xor    ax, ax
  466.     xchg    al, dh            ; ax = row, dx = col
  467.     lea    si, [@@vidmode]
  468.     call    zputc C, ax, dx, cx, bx, si
  469.     pop    dx si ax cx
  470.     mov    bl, 1
  471.     inc    dl            ; next column
  472.     cmp    dl, [BYTE @@ncol]
  473.     jb    @@colloop
  474.     cmp    cx, ax            ; last char written ?
  475.     je    @@nextline
  476.     mov    ax, cx
  477.     jmp    @@writechars
  478. @@nextline:
  479.     inc    dh             ; next line
  480.     cmp    dh, [BYTE @@maxrow]    ; line out of window ?
  481.     jnb    @@return
  482.     cmp    dh, [BYTE @@nrow]
  483.     jb    @@rowloop
  484. @@return:
  485.     ret
  486. ENDP    rest_scr
  487.  
  488.     END
  489.